package com.cskt.beyondplatform.controller;

import com.cskt.beyondplatform.pojo.*;
import com.cskt.beyondplatform.service.AppInfoService;
import com.cskt.beyondplatform.service.CategoryService;
import com.cskt.beyondplatform.service.DataDictionaryService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author admin
 **/
@Controller
public class AppController {
    @Resource
    private AppInfoService appInfoService;
    @Resource
    private DataDictionaryService dataDictionaryService;
    @Resource
    private CategoryService categoryService;

    /**
     * 分页查询app信息
     * 1、查询当前页的数据---根本
     * 2、分页信息，包括总数量、总页数、当前页-- 总数量为核心
     * 3、下拉列表参数--分类、所属平台
     * 4、参数回显--为了在翻页时条件不丢失
     *
     * @param model 数据模型
     * @param param 查询条件
     * @return 逻辑视图
     */
    @RequestMapping(value = "/manager/backend/app/list", method = {RequestMethod.GET, RequestMethod.POST})
    public String appList(Model model, QueryAppInfoParam param) {
        //    1、分页查询未审核 列表；
        //    先要的当前页计算起始下标
        List<AppInfoVO> appInfoVOS = appInfoService.selectAppInfoVOByPage(param);
        Integer total = appInfoService.countAppInfo(param);

        PageVO pageVO = new PageVO();
        pageVO.setTotalCount(total);
        pageVO.setCurrentPageNo(param.getPageIndex());

        model.addAttribute("appInfoList", appInfoVOS);
        model.addAttribute("pages", pageVO);
        //    2、查询条件下拉列表----应用一级分类；
        List<AppCategory> categoryLevel1List = categoryService.getCategoryByParentId(null);
        // 3、查询条件下列列表----所属平台；
        List<DataDictionary> flatformList = dataDictionaryService.getDataDictionaryByTypeCode("APP_FLATFORM");
        model.addAttribute("flatFormList", flatformList);
        model.addAttribute("categoryLevel1List", categoryLevel1List);

        //响应时，将选择的条件带回，条件回显
        model
                .addAttribute("queryCategoryLevel1", param.getQueryCategoryLevel1())
                .addAttribute("queryCategoryLevel2", param.getQueryCategoryLevel2())
                .addAttribute("queryCategoryLevel3", param.getQueryCategoryLevel3())
                .addAttribute("querySoftwareName", param.getQuerySoftwareName())
                .addAttribute("queryFlatformId", param.getQueryFlatformId());


        return "backend/applist";
    }

    /**
     * 分类的父级分类id,也就是parent_id
     *
     * @param pid
     * @return
     */
    @GetMapping(value = "/categorylevellist.json")
    @ResponseBody
    public List<?> categorylevellist(Long pid) {
        //    select * from app_category where parent_id = ${pid,jdbcType=Long}
        return Arrays.asList();
    }

}
